n = int(input())

if len(str(n)) == 4 and n > 999:
    a = int(str(n)[0])
    b = int(str(n)[1])
    c = int(str(n)[2])
    d = int(str(n)[3])
    q = int(str(a)+str(b))
    w = int(str(b)+str(c))
    e = int(str(c)+str(d))
    r = int(str(a)+str(b)+str(c))
    t = int(str(b)+str(c)+str(d))
    y = int(str(a)+str(b)+str(c)+str(d)) 
    x1 = 0
    for i in range(1,a+1):
        if a%i == 0:
            x1 += 1
    if x1 != 2:
        a = 0
    x2 = 0
    for i in range(1,b+1):
        if b%i == 0:
            x2 += 1
    if x2 != 2:
        b = 0
    x3 = 0
    for i in range(1,c+1):
        if c%i == 0:
            x3 += 1
    if x3 != 2:
        c = 0
    x4 = 0
    for i in range(1,d+1):
        if d%i == 0:
            x4 += 1
    if x4 != 2:
        d = 0
    
    x5 = 0
    for i in range(1,q+1):
        if q%i == 0:
            x5 += 1
    if x5 != 2:
        q = 0
    x6 = 0
    for i in range(1,w+1):
        if w%i == 0:
            x6 += 1
    if x6 != 2:
        w = 0
    x7 = 0
    for i in range(1,e+1):
        if e%i == 0:
            x7 += 1
    if x7 != 2:
        e = 0
    x8 = 0
    for i in range(1,r+1):
        if r%i == 0:
            x8 += 1
    if x8 != 2:
        r = 0
    x9 = 0
    for i in range(1,t+1):
        if t%i == 0:
            x9 += 1
    if x9 != 2:
        t = 0
    x10 = 0
    for i in range(1,y+1):
        if y%i == 0:
            x10 += 1
    if x10 != 2:
        y = 0
    s = [a,b,c,d,q,w,e,r,t,y]
    z = 0
    for i in s:
        if i > z:
            z = i
    print(z)    
else:
    print(0)
